#ifndef ENTITYMODEL_H
#define ENTITYMODEL_H

#include <QAbstractTableModel>
#include <QtGui>
#include <QTextStream>
#include <QItemSelection>
#include "aed_entity.h"
#include "archtypemodel.h"

class EntityModel : public QAbstractTableModel
{
    Q_OBJECT

    QList<AED_Entity> m_ents;
public:
    explicit EntityModel(QObject *parent = 0);

    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int columnCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
    QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    Qt::ItemFlags flags(const QModelIndex &index) const;

    AED_Entity* AddEntity(AED_Archtype *arch);
    void CopySelectedEntities();
    //void UpdateArchtype(const AED_Archtype &arch, int index);
    void EraseSelectedEntities();
    void EraseEntitiesByArchtype(AED_Archtype *arch);
    void Clean();
    int CountEntitiesByArchtype(AED_Archtype *arch);

    void ClearImage(const QString name);

    QList<AED_Entity>* GetEntities(){return &m_ents;}
    AED_Entity& GetEntity(int index);
    void Save(QTextStream &file);
    void Save(QDomDocument &doc, QDomElement &header);

    bool Load(QDomElement &header, ArchtypeModel &archmodel);
signals:
    void SelectionUpdated();
public slots:
    void UpdateSelection(QItemSelection selected,QItemSelection deselected);
};

#endif // ENTITYMODEL_H
